//
//  ViewController.m
//  LBScrollViewRefreshAndMoreDemo
//
//  Created by 刘文扬 on 2017/9/20.
//  Copyright © 2017年 lianj. All rights reserved.
//

#import "ViewController.h"
#import "UIScrollView+LBRefreshAndMoreTableView.h"
#import <Masonry.h>
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

/** tableView*/
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataSouces;

@end

@implementation ViewController
-(UITableView *)tableView
{
    
    if (_tableView == nil) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.rowHeight = 60;
        _tableView.tableFooterView = [UIView new];
        if (@available(iOS 11.0, *)) {
            [_tableView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAlways];
        } else {
            // Fallback on earlier versions
        }
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Demo";
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    __weak ViewController *weakSelf = self;
    [self.tableView addRefreshAction:^{
        [weakSelf refreshData];
    } loadMoreAction:^{
        [weakSelf loadMoreData];
    }];
    [self.tableView begainRefresh];
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)refreshData{

    
    _dataSouces = [NSMutableArray arrayWithArray:@[@"语文",@"数学",@"政治",@"体育",@"英文",@"编程",@"画画",@"PHP",@"JAVA",@"Objective-C",@"Python",@"Laravel"]];
    [self.tableView reloadData];
    [self.tableView endFresh];
}
- (void)loadMoreData{
    [_dataSouces addObjectsFromArray:@[@"语文1",@"数学1",@"政治1",@"体育1",@"英文1",@"编程1",@"画画1",@"PHP1"]];
    [self.tableView reloadData];
    [self.tableView endLoadMoreWithNoMoreData];
}
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    NSString *cellID = @"identity";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.textLabel.text = _dataSouces[indexPath.row];
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSouces.count;
}


@end
